<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
<#include "../common/header.ftl">
    <script type="text/javascript" src="/js/plugins/chosen/chosen.jquery.js"></script>
    <script type="text/javascript" src="/js/plugins/ckeditor/ckeditor.js"></script>
    <link rel="stylesheet" href="/js/plugins/chosen/component-chosen.css" type="text/css" />

    <style type="text/css">
        .chosen-container {
            width: 250px !important;
        }

        .modal-body img {
            width: 300px
        }

        .modal-content-content {
            height: 460px;
            overflow-y: scroll;
        }
    </style>

    <script type="text/javascript">

        $(function(){
            $('#pagination').twbsPagination({
                        totalPages:${result.pages}||1,
                    startPage:${result.pageNum},
            visiblePages:${result.pageSize},
            first:"首页",
                    prev:"上页",
                    next:"下页",
                    last:"尾页",
                    onPageClick:function(event, page){
                //讲当前页设置page值
                $("#currentPage").val(page);
                //表单提交gjk,mb/.
                $("#searchForm").submit();
            }
        });

            //修改按钮
            $(".editBtn").click(function(){

                $("#editForm")[0].reset();

                var json = $(this).data("json");

                $("#newsId").val(json.id);
                $("#title").val(json.title);
                $("#sequence").val(json.sequence);
                $("#state").val(json.state+'');
                $("#coverImg").attr('src',json.coverUrl);
                $("#coverUrl").val(json.coverUrl);

                $("#coverImg").attr('width','50%')
                //回显表单中的攻略下拉框
                $("#strategy option[value="+json.strategyId+"]").prop('selected',true)
                //让插件执行更新操作
                $("#strategy").trigger("chosen:updated")

                $.get('/strategyCatalog/listByStrategyId.do', {id: json.strategyId}, function (data) {
                    var html = "<option></option>";

                    //循环取出data中的数据
                    $.each(data, function (index, ele) {
                        html += "<option value='" + ele.id + "'>" + ele.name + "</option>"

                    })

                    $("#strategyCatalog").html(html)



                    $("#strategyCatalog").trigger("chosen:updated")
                })

                //回显文章内容
                $.get('/news/getContenById.do',{id:json.id},function(data){
                    ckeditor.setData(data.content)
                })

                $("#newsModal").modal('show');
            })


            //保存按钮
            $("#saveBtn").click(function () {

                //提交表单前,先获取内容,再设置进去,一并提交
                //把编辑器的内容,设置到textarea
                var data = ckeditor.getData();
                $("#editor").val(data)

                $("#editForm").ajaxSubmit(function (data) {
                    if(data.success){
                        $.messager.confirm("温馨提示","操作成功!",function () {
                            window.location.reload();
                        })
                    }else{
                        $.messager.alert("错误信息",data.msg);
                    }
                })
            })

            //新增按钮
            $(".addBtn").click(function () {
                $("#editForm")[0].reset()
                //$("#coverImg").attr('src','')
                $("#coverImg").attr('width','0')
                $("#newsModal").modal('show')
            })

            //查看文章内容
            $(".showContentBtn").click(function(){
                //获取游记的id
                var id= $(this).data("tid")
                $.get('/news/getNewsContentById.do',{id:id},function(data){
                    $("#newsContent").html(data.content)
                    $("#contentModal").modal('show')
                })
            })

            //发布 & 拒绝
            $(".changeSateBtn").click(function(){
                //获取游记的id
                var id = $(this).data("tid");
                //获取要修改的状态
                var state = $(this).data("state");
                $.get("/news/changeState.do",{id:id,state:state},function(data){
                    if(data.success){
                        $.messager.confirm("温馨提示","操作成功!",function () {
                            window.location.reload();
                        })
                    }else{
                        $.messager.alert("错误信息",data.msg);
                    }
                })
            })


            //初始化ck编辑器
            var ckeditor = CKEDITOR.replace( 'editor',{
                height:300
            });
        })


    </script>
</head>
<body>
<div class="container " style="margin-top: 20px">
<#include "../common/top.ftl">
    <div class="row">
        <div class="col-sm-3">
        <#include "../common/menu.ftl">
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">攻略文章管理</h1>
                </div>
            </div>
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="/news/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">

                <div class="form-group">
                    <label for="keyword">关键字:</label>
                    <input type="text" class="form-control" id="keyword" name="keyword" value="${(qo.keyword)!}" placeholder="日报标题">
                </div>
                <div class="form-group">
                    <label for="state">状态:</label>
                    <select class="form-control" id="state" name="state">
                        <option value="-2">全部</option>
                        <option value="1">待发布</option>
                        <option value="-1">已拒绝</option>
                    </select>
                    <script>
                        $('#state option[value='+'${(qo.state)!}'+']').prop('selected',true);
                    </script>
                </div>

                <button id="btn_query" class="btn btn-default">查询</button>
                <button type="button"  class="btn btn-success addBtn">新增</button>
            </form>

            <div id="catalogname">
                <table class="table table-striped table-hover" >
                    <thead>
                    <tr>
                        <th>编号</th>
                        <th>标题</th>
                        <th>封面</th>
                        <th>发布时间</th>
                        <th>日报类型</th>
                        <th>发布类型</th>
                    </thead>
                <#list result.list as entity>
                    <tr>
                        <td>${entity_index+1}</td>
                        <td>${entity.title}</td>
                        <td><img src="${(entity.coverUrl)!}" width="30px"/> </td>
                        <td>${((entity.releaseTime)?string("yyyy-MM-dd"))!}</td>
                        <td>${(entity.type.name)!}</td>
                        <td>
                            <#if entity.state==-1>
                                拒绝
                            <#elseif entity.state==0>
                                草稿
                            <#elseif entity.state==1>
                                待发布
                            <#elseif entity.state==2>
                                已发布
                            </#if>
                        </td>
                        <td><a href="javascript:void(0);" class="changeSateBtn" data-state="2" data-tid='${entity.id}'>发布</a></td>
                        <td><a href="javascript:void(0);" class="changeSateBtn" data-state="-1" data-tid='${entity.id}'>拒绝</a></td>
                        <td><a href="javascript:void(0);" class="showContentBtn" data-tid='${entity.id}'>查看内容</a></td>
                      <#--  <td><a href="javascript:void(0);" class="editBtn" data-json='${entity.jsonString}'>修改</a></td>-->
                    </tr>
                </#list>
                </table>
            </div>
            <div style="text-align: center;">
                <ul id="pagination" class="pagination"></ul>
            </div>
        </div>
    </div>
</div>



<div class="modal fade" id="newsModal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">新增/修改</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/news/saveOrUpdate.do" method="post" id="editForm"  enctype="multipart/form-data" >
                    <input type="hidden"  id="newsId" name="id">
                    <div class="form-group" >
                        <label for="name" class="col-sm-4 control-label">标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="title" name="title"  >
                        </div>
                    </div>
                    <div class="form-group" >
                        <label for="name" class="col-sm-4 control-label">封面：</label>
                        <div class="col-sm-6">
                            <img id="coverImg" width="50%" />
                            <input type="hidden" class="form-control" id="coverUrl" name="coverUrl"  >
                            <input type="file" class="form-control" id="coverFile" name="file"  >
                        </div>
                    </div>

                    <div class="form-group" >
                        <label for="name" class="col-sm-4 control-label">是否发布：</label>
                        <div class="col-sm-6">
                            <select class="form-control" name="state" id="state">
                                <option value="1" selected>否</option>
                                <option value="2">是</option>
                            </select>
                        </div>
                    </div>

                    <div class="form-group" >
                    <textarea name="content.content" id="editor" rows="10" cols="80">

                    </textarea>

                    </div>

                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-success" id="saveBtn">保存</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<#--查看日报内容-->
<div class="modal fade" id="contentModal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">查看游记内容</h4>
            </div>
            <div class="modal-content-content" id="newsContent" >


            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

</body>
</html>